package com.yin.configuration;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

/**
*@author LSY
*Time: 2018年12月26日下午2:24:03
*
*
*/
@Configuration
public class FastJsonConfiguration implements WebMvcConfigurer{

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		//消息转换器
		FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
		//配置类
		FastJsonConfig fastJsonConfig = new FastJsonConfig();
/*		//类型转换
		List<MediaType> fastMediaTypes = new ArrayList<>();
		
        fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
        
        fastConverter.setSupportedMediaTypes(fastMediaTypes);*/
        //修改配置返回内容
        fastJsonConfig.setSerializerFeatures(
				SerializerFeature.WriteNullStringAsEmpty,
				SerializerFeature.DisableCircularReferenceDetect,
				SerializerFeature.WriteMapNullValue
				);
		fastConverter.setFastJsonConfig(fastJsonConfig);
		//将fastjson添加到视图消息转换器列表
		converters.add(fastConverter);
	}
}
